package com.xuzm.demo.util;

import org.springframework.util.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class PersDateUtils {
    public static final String FORMAT_DATE_SPLIT = "yyy-MM-dd";
    public  static final String FORMAT_DATE_NONE = "yyyyMMdd";
    public static final String FORMAT_DATE_TIME ="yyyy-MM-dd HH:mm:ss:SSS";
    public static final String FORMAT_FULL_DATE_TIME = "yyyyMMddHHmmssSSS";
    public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
    public static SimpleDateFormat getSdf(String pattern){
        return new SimpleDateFormat(pattern);
    }
    public static Date getDate(){
        return new Date();
    }
    public static Calendar getCalendar(){
        return Calendar.getInstance();
    }
    public static String getPatternDate(String pattern,Date date){
        return getSdf(pattern).format(date);
    }
    public static Date str2Date(String string,  SimpleDateFormat simpleDateFormat){
        if(StringUtils.isEmpty(string)){
            return null;
        }
        Date date = null;
        try{
            date = simpleDateFormat.parse(string);
            return date;
        }catch (Exception e){

        }
        return null;
    }
}
